package com.java.al.swing.toolbar;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolBar;

public class Toolbars {
  public static void main(String[] args) {
	  


    JToolBar toolbar1 = new JToolBar();
    JToolBar toolbar2 = new JToolBar();
    toolbar1.setRollover(true);
    toolbar2.setRollover(true);
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    JButton newb = new JButton(new ImageIcon("new.png"));
    JButton openb = new JButton(new ImageIcon("open.png"));
    JButton saveb = new JButton(new ImageIcon("src/swing/toolbar/toolbar/3.gif"));

    toolbar1.add(newb);
    
    toolbar1.add(openb);
    toolbar1.add(saveb);
    saveb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
          System.out.println("保存");
        }
      });
    toolbar1.setAlignmentX(0);

    JButton exitb = new JButton(new ImageIcon("src/swing/toolbar/toolbar/8.gif"));
    toolbar2.add(exitb);
    toolbar2.setAlignmentX(0);

    exitb.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent event) {
        System.exit(0);
      }
    });

    panel.add(toolbar1);
    panel.add(toolbar2);

    JFrame f = new JFrame();
    f.add(panel, BorderLayout.NORTH);

    f.setSize(300, 200);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  }
}